<?php

namespace App\Controllers;

use Xxh\Bos\BosStorage;

class ImgController extends  Collect
{



    public function initUrls()
    {

        if( $this->checkUrl()) {
            preg_match('|(\d+)|',$this->url,$res);
            if( count($res) <2) return;
            $this->hbilbil($res[1]);
        } else {
            $content = resolve('request')->send($this->url);
            $imgs = resolve('match')->findImg($content);
            $this->urls = $imgs;
        }

    }





    //哔哩哔哩的相簿api
    public function hbilbil($id)
    {


        $url = 'https://api.vc.bilibili.com/link_draw/v1/doc/detail?doc_id='.$id;
        $content = resolve('request')->getContent($url);
        $content = json_decode($content);
        $pictures = $content->data->item->pictures;
        foreach ($pictures as $picture)
            $this->urls[] = $picture->img_src;
    }



    //是否要特别处理的url
    public function checkUrl()
    {

        $checkList = ['h.bilibili.com'];
        if( in_array($this->host,$checkList)){
            return true;
        }
        return false;
    }


    public function __destruct()
    {

        //$this->zip();
    }


}
